﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TMDT_Nhom1A.DAO;
using TMDT_Nhom1A.DTO;

namespace TMDT_Nhom1A.BUS
{
    public class OrderB2B_BUS
    {
        public static void SaveOrderB2B(ORDER_B2B order, Cart cart)
        {
            string orderb2b_id = "";
            OrderB2B_DAO.GetOrderB2B_ID(order.UserID, ref orderb2b_id);
            if (orderb2b_id != "")
                OrderB2B_BUS.DeleteCart(orderb2b_id);
            OrderB2B_DAO.SaveOrderB2B(order,ref orderb2b_id);
            for (int i = 0; i < cart.GetList().Count; i++)
            {
                ORDER_DETAIL detailorder = new ORDER_DETAIL();
                detailorder.ElectricDevice_ID = cart.GetList()[i].ElectricDeviceID;
                detailorder.OrderB2B_ID = orderb2b_id;
                detailorder.Quantity = cart.GetList()[i].Quantity;
                detailorder.Cost = cart.GetList()[i].TotalPrice;
                OrderB2B_DAO.SaveDetailOrderB2B(detailorder);
            }

        }

        public static void GetOrderID(int UserID, ref string OrderB2B_ID)
        {
            OrderB2B_DAO.GetOrderB2B_ID(UserID, ref OrderB2B_ID);
        }

        public static void DeleteCart(string OrderB2B_ID)
        {
            OrderB2B_DAO.DeleteCart(OrderB2B_ID);
        }

        public static Cart GetSaveDetailOrderB2B(string UserID)
        {
            return OrderB2B_DAO.GetSaveDetailOrderB2B(UserID);
        }

        public static void DeleteDetailOrderB2B(ORDER_DETAIL order)
        {
            OrderB2B_DAO.DeleteDetailOrderB2B(order);
        }

        public static bool checkExistOrderB2BID(string orderB2BID)
        {
            return OrderB2B_DAO.checkExistOrderB2BID(orderB2BID);
        }
    }
}
